<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<style>
    table tr th, table tr td {
        border-color: #000000;
        text-align: center;
        vertical-align: middle;
        font-size: 16px;
        line-height: 30px;
        border: #000000 1px solid;
    }
    table tr td input {
        border: none;
        width: 100%;
        height: 30px;
        outline: none;
        text-align: center;
    }
    table tr td textarea {
        border: none;
        width: 100%;
        height: 30px;
        outline: none;
        resize: none;

    }
    .changeCursorIco {
        cursor: pointer !important;
    }
</style>
<body class="hold-transition skin-yellow sidebar-mini">
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box" style="box-shadow:none;border:none;">
                <div class="box-body">
                    <div class="col-md-12" style="padding-bottom: 25px;">
                        <button id="btn_scheduling_complete" class="btn btn-success pull-right"
                                shiro:hasPermission="pro:other:edit"
                                style="margin-right: 5px;"
                                th:data-prodOrdNo="${prodOrd.prodNo}" onclick="saveCommonSchedulingComplete(this)"
                                type="button">保存
                        </button>
                    </div>
                    <div class="col-md-12" style="padding-left: 205px;padding-right: 145px;">
                        <form id="dataForm">
                            <table id="formTable" width="100%" border="0" cellpadding="0" cellspacing="0" style="z-index: -2">
                                <tr id="tableTitle1">
                                    <td colspan="6"
                                        style="font-size: 20px;height: 35px">
                                        <B>其他类项目排产</B>
                                    </td>
                                    <td style="border:none">
                                    </td>
                                </tr>
                                <tr id="prodInfo">
                                    <td style="width: 100px;">项目编号</td>
                                    <td style="width:200px;" th:text="${prodOrd.prodNo}"></td>
                                    <td style="width:200px;">项目名称</td>
                                    <td style="width:200px;" th:text="${prodOrd.prodName}"></td>
                                    <td style="width:200px;">数量</td>
                                    <td th:text="${prodOrd.prodNum}"></td>
                                    <td style="border:none">
                                    </td>
                                </tr>
                                <tr id="proInfo">
                                    <td>安装地点</td>
                                    <td th:text="${prodOrd.insSite}"></td>
                                    <td>需方</td>
                                    <td th:text="${prodOrd.customer}"></td>
                                    <td>交货时间</td>
                                    <td th:text="${#dates.format(prodOrd.prodDelDat, 'yyyy-MM-dd')}"></td>
                                    <td style="border:none">
                                    </td>
                                </tr>
                                <tr id="tableTitle2">
                                    <td colspan="6"
                                        style="font-size: 20px;height: 35px">
                                        <B>项目排产</B>
                                    </td>
                                    <td style="border:none">
                                    </td>
                                </tr>
                                <tr id="tableTitle3">
                                    <td>序号</td>
                                    <td>任务节点名称</td>
                                    <td>计划开始时间</td>
                                    <td>计划结束时间</td>
                                    <td>所属部门</td>
                                    <td>备注</td>
                                    <td name="oper" style="border:none;width:60px;">
                                        <button id="btn_addRow" type="button" class="pull-left" onclick="addRow(this)"
                                                style="border:none;background:transparent;color:green;font-size: 18px">
                                            <i class="fa fa-plus"></i></button>
                                    </td>
                                </tr>
                            </table>
                        </form>
                    </div>
                    <div class="col-md-10 col-md-offset-1"
                         style="font-size: 16px;font-family:'Source Sans Pro','Helvetica Neue',Helvetica,Arial,sans-serif;line-height: 30px;">
                        <div class="form-inline">
                            <div class="form-group pull-left">
                                <label class="control-label">
                                    创建人：
                                </label>
                                <label id="fou" th:text="${fou}" class="control-label"></label>
                            </div>
                            <div class="form-group pull-right" style="margin-right: 60px;">
                                <label class="control-label">
                                    创建时间：
                                </label>
                                <label id="creDat" th:text="${creDat}" class="control-label"></label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let planData, planOptionList, delPrpdIdArray = new Array(),deptList,deptOptionList,publicProdNo=[[${prodOrd.prodNo}]];
    let isHaveProduction = false;
    /**
     * Jquery 就绪函数
     */
    $(function () {
        //加载计划数据
        loadPlanTemplateData();
    });

    /**
     * 添加新行
     */
    function addRow(obj) {
        let tdEl = new Array();
        let newOrderNo = getNewOrderNo();
        tdEl.push('<td name="orderNo">' + newOrderNo + '</td>');
        tdEl.push('<td><div class="list-name-input">' + planOptionList + '</div></td>');
        tdEl.push('<td><input class="changeCursorIco" name="prpdPlaStaDat" type="text" style="outline：none;" readOnly="readonly" alt="点击选择开始时间"/></td>');
        tdEl.push('<td><input class="changeCursorIco" name="prpdPlaEndDat" type="text" style="outline：none;" readOnly="readonly" alt="点击选择结束时间"/></td>');
       let deptSelect = "<select class='form-control' name='prpdDepId' style='border:none;outline：none;'>";
        deptSelect += "<option value=''>&nbsp;</option>";
        for (let i = 0; i < deptList.length; i++) {
            deptSelect += "<option value='" + deptList[i].id + "'>" + deptList[i].name + "</option>";
        }
        deptSelect += "</select>";
        tdEl.push('<td>'+deptSelect+'</td>');
        tdEl.push('<td><textarea class="form-control" name="prpdRem" type="text" maxlength="255" style="outline：none;border: none;width: 100%;height: 30px;outline: none;resize: none;"></textarea></td>');
        tdEl.push('<td name="oper" style="border:none;width:60px;"><button type="button" class="pull-left" onclick="addRow(this)" style="border:none;background:transparent;color:green;font-size: 18px"><i class="fa fa-plus"></i></button><button onclick="subtractRow(this)" style="border:none;background:transparent;color:red;font-size: 18px"> <i class="fa fa-close"></i></button></td>');
        $(obj).parent().parent().after('<tr id="dataRow_' + newOrderNo + '">' + tdEl + '</tr>')
        $("#formTable [name='prpdPlaStaDat']").datepicker({
            format: "yyyy-mm-dd",
            language: "zh-cn",
            autoclose: true,
            todayHighlight: true,
            clearBtn: true
        });
        $("#formTable [name='prpdPlaEndDat']").datepicker({
            format: "yyyy-mm-dd",
            language: "zh-cn",
            autoclose: true,
            todayHighlight: true,
            clearBtn: true
        });
        $(obj).parent().html('');
        if(isHaveProduction===false){
            $("#dataRow_"+newOrderNo).find("[name='prpdNamSelect']").val('生产完成时间').change();
            isHaveProduction=true;
        }
    }

    /**
     * 移除本行
     */
    function subtractRow(obj) {
        if($(obj).parent().parent().find("[name='prpdId']").val()!=null && $(obj).parent().parent().find("[name='prpdId']").val() != ''){
            delPrpdIdArray.push($(obj).parent().parent().find("[name='prpdId']").val());
        }
        $(obj).parent().parent().remove();
        let lastId = $('#formTable tr:last').attr('id');
        if (lastId === 'tableTitle3') {
            $('#formTable tr:last').find("[name='oper']").html('<button type="button" class="pull-left" onclick="addRow(this)" style="border:none;background:transparent;color:green;font-size: 18px"><i class="fa fa-plus"></i></button>');
        } else {
            $('#formTable tr:last').find("[name='oper']").html('<button type="button" class="pull-left" onclick="addRow(this)" style="border:none;background:transparent;color:green;font-size: 18px"><i class="fa fa-plus"></i></button><button onclick="subtractRow(this)" style="border:none;background:transparent;color:red;font-size: 18px"> <i class="fa fa-close"></i></button>');
        }
        //重新排序
        let index = 1;
        $("#formTable tr [name='orderNo']").each(function () {
            $(this).html(index);
            index++;
        });
    }

    /**
     * 获取最新行号
     */
    function getNewOrderNo() {
        let rowIndex = 1;
        $("#formTable tr").each(function () {
            let idText = $(this).attr("id");
            if (idText.indexOf("dataRow") > -1) {
                rowIndex++;
            }
        });
        return rowIndex;
    }

    /**
     * 验证当结束时间是否大于开始时间
     */
    function verificationStart(obj) {
        let startVal = $(obj).val();
        let endVal = $(obj).parent().parent().find("[name='planEndTime']").val();
        if (startVal != undefined && endVal != undefined) {
            let start = new Date(startVal);
            let end = new Date(endVal);
            if (end <= start) {
                $(obj).val('');
                js.modal.warning("尊敬的用户，您所输入的开始时间必须大于结束时间！");
            }
        }
    }

    /**
     * 验证当结束时间是否大于开始时间
     */
    function verificationEnd(obj) {
        let endVal = $(obj).val();
        let startVal = $(obj).parent().parent().find("[name='planStartTime']").val();
        if (startVal != undefined && endVal != undefined) {
            let end = new Date($(obj).val());
            let start = new Date($(obj).parent().parent().find("[name='planStartTime']").val());
            if (end <= start) {
                $(obj).val('');
                js.modal.warning("尊敬的用户，您所输入的结束时间必须大于开始时间！");
            }
        }
    }

    /**
     * 排产
     */
    function saveCommonSchedulingComplete(obj) {
        let dataArray = new Array();
        let dataModel = new Object();
        let warningInfo = '';
        let index = 1;
        let warningInfo2 = '';
        let index2 = 1;
        let prpdNamArray = new Array();
        let warningInfoEndDat = '';
        let indexEndDat = 1;
        let warningInfoDep = '';
        let indexEndDep = 1;
        $.each($("#dataForm").serializeArray(), function (_, kv) {
            if (kv.name === 'prpdNam') {
                if (kv.value === '') {
                    warningInfo += "第" + index + "行、";
                    index++
                } else if (prpdNamArray.indexOf(kv.value) > -1) {
                    warningInfo2 += "第" + index2 + "行、";
                    index2;
                } else if (prpdNamArray.indexOf(kv.value) === -1) {
                    prpdNamArray.push(kv.value);
                }
            }
            if (kv.name === 'prpdPlaEndDat') {
                if (kv.value === "") {
                    warningInfoEndDat += "第" + indexEndDat + "行、";
                    indexEndDat++;
                }
            }
            if (kv.name === 'prpdDep') {
                if (kv.value === "") {
                    warningInfoDep += "第" + indexEndDep + "行、";
                    indexEndDep++;
                }
            }
        });
        if (warningInfo.length > 0 || warningInfo2.length > 0) {
            if (warningInfo.length > 0) {
                warningInfo = warningInfo.substring(0, warningInfo.length - 1);
                js.modal.warning("尊敬的用户，请选择" + warningInfo + "任务节点名称！");
            }
            if (warningInfo2.length > 0) {
                warningInfo2 = warningInfo2.substring(0, warningInfo2.length - 1);
                js.modal.warning("尊敬的用户，您选择" + warningInfo2 + "任务节点名称出现重复，请修改！");
            }
            if (warningInfoEndDat.length > 0) {
                warningInfoEndDat = warningInfoEndDat.substring(0, warningInfoEndDat.length - 1);
                js.modal.warning("尊敬的用户，请选择" + warningInfoEndDat + "结束时间！");
            }
            if (warningInfoDep.length > 0) {
                warningInfoDep = warningInfoDep.substring(0, warningInfoDep.length - 1);
                js.modal.warning("尊敬的用户，请填写" + warningInfoDep + "所属部门！");
            }
            return;
        }
        let indexNo = 0;
        $.each($("#dataForm").serializeArray(), function (_, kv) {
            if (kv.name === 'prpdNam') {
                dataModel.prpdNam = kv.value;
            }
            if (kv.name === 'prpdCod') {
                if(kv.value != ""){
                    dataModel.prpdCod = kv.value;
                }else {
                    dataModel.prpdCod = null;
                }
            }
            if (kv.name === 'prpdOrdNo') {
                if (kv.value != "") {
                    dataModel.prpdOrdNo = kv.value;
                }else{
                    dataModel.prpdOrdNo =indexNo;
                    indexNo++;
                }
            }
            if (kv.name === 'prpdPlaStaDat') {
                if (kv.value != "") {
                    dataModel.prpdPlaStaDat = kv.value;
                } else {
                    dataModel.prpdPlaStaDat = null;
                }
            }
            if (kv.name === 'prpdPlaEndDat') {
                if (kv.value != "") {
                    dataModel.prpdPlaEndDat = kv.value;
                } else {
                    dataModel.prpdPlaEndDat = null;
                }
            }
            if (kv.name === 'prpdDepId') {
                if (kv.value != "") {
                    dataModel.prpdDepId = kv.value;
                } else {
                    dataModel.prpdDepId = null;
                }
            }
            if (kv.name === 'prpdRem') {
                if (kv.value != "") {
                    dataModel.prpdRem = kv.value;
                } else {
                    dataModel.prpdRem = null;
                }
                if (dataModel.prpdNam != undefined) {
                    dataArray.push(dataModel);
                    dataModel = new Object();
                }
            }
        });
        if (dataArray.length > 0) {
            js.post({
                url: ctx + 'task/common/saveSchedulingPlanAndComplete',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: {
                    prodNo: $(obj).attr('data-prodOrdNo'),
                    prodPlanListJson: JSON.stringify(dataArray),
                    delPrpdIdArrayJson: JSON.stringify(delPrpdIdArray)
                },
                async: true,                // 异步执行
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        window.opener.reloadTable();
                        window.open('', '_self');
                        window.close();
                    } else {
                        js.modal.warning(result.msg);
                    }
                },
                error: function () {
                    js.modal.fail();
                }
            });
        } else {
            js.modal.warning("尊敬的用户，请添加排产计划！");
            return;
        }
    }

    // /**
    //  * 保存
    //  * @param obj
    //  */
    // function save(obj) {
    //     let dataArray = new Array();
    //     let dataModel = new Object();
    //     let warningInfo = '';
    //     let index = 1;
    //     let warningInfo2 = '';
    //     let index2 = 1;
    //     let prpdNamArray = new Array();
    //     let warningInfoEndDat = '';
    //     let indexEndDat = 1;
    //     let warningInfoDep = '';
    //     let indexEndDep = 1;
    //     $.each($("#dataForm").serializeArray(), function (_, kv) {
    //         if (kv.name === 'prpdNam') {
    //             if (kv.value === '') {
    //                 warningInfo += "第" + index + "行、";
    //                 index++
    //             } else if (prpdNamArray.indexOf(kv.value) > -1) {
    //                 warningInfo2 += "第" + index2 + "行、";
    //                 index2;
    //             } else if (prpdNamArray.indexOf(kv.value) === -1) {
    //                 prpdNamArray.push(kv.value);
    //             }
    //         }
    //         if (kv.name === 'prpdPlaEndDat') {
    //             if (kv.value === "") {
    //                 warningInfoEndDat += "第" + indexEndDat + "行、";
    //                 indexEndDat++;
    //             }
    //         }
    //         if (kv.name === 'prpdDep') {
    //             if (kv.value === "") {
    //                 warningInfoDep += "第" + indexEndDep + "行、";
    //                 indexEndDep++;
    //             }
    //         }
    //     });
    //     if (warningInfo.length > 0 || warningInfo2.length > 0) {
    //         if (warningInfo.length > 0) {
    //             warningInfo = warningInfo.substring(0, warningInfo.length - 1);
    //             js.modal.warning("尊敬的用户，请选择" + warningInfo + "任务节点名称！");
    //         }
    //         if (warningInfo2.length > 0) {
    //             warningInfo2 = warningInfo2.substring(0, warningInfo2.length - 1);
    //             js.modal.warning("尊敬的用户，您选择" + warningInfo2 + "任务节点名称出现重复，请修改！");
    //         }
    //         if (warningInfoEndDat.length > 0) {
    //             warningInfoEndDat = warningInfoEndDat.substring(0, warningInfoEndDat.length - 1);
    //             js.modal.warning("尊敬的用户，请选择" + warningInfoEndDat + "结束时间！");
    //         }
    //         if (warningInfoDep.length > 0) {
    //             warningInfoDep = warningInfoDep.substring(0, warningInfoDep.length - 1);
    //             js.modal.warning("尊敬的用户，请填写" + warningInfoDep + "所属部门！");
    //         }
    //         return;
    //     }
    //     $.each($("#dataForm").serializeArray(), function (_, kv) {
    //         if (kv.name === 'prpdNam') {
    //             dataModel.prpdNam = kv.value;
    //         }
    //         if (kv.name === 'prpdCod') {
    //             dataModel.prpdCod = kv.value;
    //         }
    //         if (kv.name === 'prpdOrdNo') {
    //             dataModel.prpdOrdNo = kv.value;
    //         }
    //         if (kv.name === 'prpdPlaStaDat') {
    //             if (kv.value != "") {
    //                 dataModel.prpdPlaStaDat = kv.value;
    //             } else {
    //                 dataModel.prpdPlaStaDat = null;
    //             }
    //         }
    //         if (kv.name === 'prpdPlaEndDat') {
    //             if (kv.value != "") {
    //                 dataModel.prpdPlaEndDat = kv.value;
    //             } else {
    //                 dataModel.prpdPlaEndDat = null;
    //             }
    //         }
    //         if (kv.name === 'prpdDep') {
    //             if (kv.value != "") {
    //                 dataModel.prpdDep = kv.value;
    //             } else {
    //                 dataModel.prpdDep = null;
    //             }
    //         }
    //         if (kv.name === 'prpdRem') {
    //             if (kv.value != "") {
    //                 dataModel.prpdRem = kv.value;
    //             } else {
    //                 dataModel.prpdRem = null;
    //             }
    //             if (dataModel.prpdNam != undefined) {
    //                 dataArray.push(dataModel);
    //                 dataModel = new Object();
    //             }
    //         }
    //     });
    //     if (dataArray.length > 0) {
    //         js.modal.confirm('尊敬的用户，您确定要保存其他类项目排产计划吗？', function () {
    //             js.post({
    //                 url: ctx + 'task/common/saveSchedulingPlan',
    //                 type: 'post',
    //                 traditional: true,            // 阻止深度序列化， 使参数可以使用数组
    //                 dataType: 'json',
    //                 contentType: "application/x-www-form-urlencoded",
    //                 data: {
    //                     prodNo: $(obj).attr('data-prodOrdNo'),
    //                     prodPlanListJson: JSON.stringify(dataArray),
    //                     delPrpdIdArrayJson: JSON.stringify(delPrpdIdArray)
    //                 },
    //                 async: true,                // 异步执行
    //                 success: function (result) {
    //                     if (result.type === web_status.SUCCESS) {
    //                         js.modal.success(result.msg);
    //                         window.opener.reloadTable();
    //                         window.open('', '_self');
    //                         window.close();
    //                     } else {
    //                         js.modal.warning(result.msg);
    //                     }
    //                 },
    //                 error: function () {
    //                     js.modal.fail();
    //                 }
    //             });
    //         });
    //     } else {
    //         js.modal.warning("尊敬的用户，请添加排产计划！");
    //         return;
    //     }
    // }

    /**
     * 加载计划数据
     */
    function loadPlanTemplateData() {
        js.post({
            url: ctx + 'task/common/loadPlanTemplateData',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {},
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    planData = result.data;
                    planOptionList = '<div style="position:relative;"><span style="margin-left:30px;height:100%;width:30px;overflow:hidden;"><select name="prpdNamSelect" style="width:180px;margin-left:-40px;border: none;outline: none" onchange="updRelDat(this)">';
                    planOptionList += "<option value=''>--请选择--</option>";
                    for (let i = 0; i < planData.length; i++) {
                        planOptionList += "<option data-propCod='" + planData[i].prpdCod + "' data-prpdOrdNo='" + planData[i].prpdOrdNo + "' value='" + planData[i].prpdNam + "'>" + planData[i].prpdNam + "</option>";
                    }
                    planOptionList += "</select ></span>";
                    planOptionList += "<input style='width:170px;position:absolute;left:0px;' name='prpdNam' maxlength='255' oninput='clearRelDat(this)'/>";
                    planOptionList += "<input name='prpdCod' type='hidden' style='display: none' value='' />";
                    planOptionList += "<input name='prpdOrdNo' type='hidden' style='display: none' value='' />";
                    planOptionList += "<input name='prpdId' type='hidden' style='display: none' value='' /></div>";
                    js.post({
                        url: ctx + 'task/common/loadDeptLis',
                        type: 'post',
                        traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                        dataType: 'json',
                        contentType: "application/x-www-form-urlencoded",
                        data: {},
                        async: true,                // 异步执行
                        success: function (result) {
                            if (result.type === web_status.SUCCESS) {
                                deptList = result.data;
                                js.post({
                                    url: ctx + 'task/common/loadExistPlanData',
                                    type: 'post',
                                    traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                                    dataType: 'json',
                                    contentType: "application/x-www-form-urlencoded",
                                    data: {
                                        prodOrdNo: $("#btn_scheduling_complete").attr('data-prodordno')
                                    },
                                    async: true,                // 异步执行
                                    success: function (result) {
                                        if (result.type === web_status.SUCCESS) {
                                            let list = result.data;
                                            if (list.length > 0) {
                                                $("#tableTitle3 [name='oper']").html('');
                                            }
                                            for (let i = 0; i < list.length; i++) {
                                                let prpdCod;
                                                if(list[i].prpdCod!=null){
                                                    prpdCod= list[i].prpdCod;
                                                    if( list[i].prpdCod==='p9'){
                                                        isHaveProduction = true;
                                                    }
                                                }else{
                                                    prpdCod='';
                                                }
                                                let prpdNam;
                                                if(list[i].prpdNam!=null){
                                                    prpdNam= list[i].prpdNam;
                                                }else{
                                                    prpdNam='';
                                                }
                                                let prpdOrdNo;
                                                if(list[i].prpdOrdNo!=null){
                                                    prpdOrdNo= list[i].prpdOrdNo;
                                                }else{
                                                    prpdOrdNo='';
                                                }
                                                let prpdId;
                                                if(list[i].prpdId!=null){
                                                    prpdId= list[i].prpdId;
                                                }else{
                                                    prpdId='';
                                                }
                                                let prpdPlaStaDat;
                                                if(list[i].prpdPlaStaDat!=null){
                                                    prpdPlaStaDat= list[i].prpdPlaStaDat;
                                                }else{
                                                    prpdPlaStaDat='';
                                                }
                                                let prpdPlaEndDat;
                                                if(list[i].prpdPlaEndDat!=null){
                                                    prpdPlaEndDat= list[i].prpdPlaEndDat;
                                                }else{
                                                    prpdPlaEndDat='';
                                                }
                                                let prpdDepId;
                                                if(list[i].prpdDepId!=null){
                                                    prpdDepId= list[i].prpdDepId;
                                                }else{
                                                    prpdDepId='';
                                                }
                                                let prpdRem;
                                                if(list[i].prpdRem!=null){
                                                    prpdRem= list[i].prpdRem;
                                                }else{
                                                    prpdRem='';
                                                }
                                                let planOptionListEml = '<div style="position:relative;"><span style="margin-left:30px;height:100%;width:30px;overflow:hidden;"><select style="width:180px;margin-left:-40px;border: none;outline: none" onchange="updRelDat(this)">';
                                                // let planOptionListEml = '<select class="form-control" name="prpdNam" onchange="updRelDat(this)" style="border:none;outline：none;">';
                                                planOptionListEml += "<option value=''>--请选择--</option>";
                                                for (let j = 0; j < planData.length; j++) {
                                                    let selected = "";
                                                    if (list[i].prpdCod === planData[j].prpdCod) {
                                                        selected = "selected='selected'";
                                                        if (list[i].prpdCod != null) {
                                                            prpdCod = list[i].prpdCod;
                                                        } else {
                                                            prpdCod = "";
                                                        }
                                                        if (list[i].prpdNam != null) {
                                                            prpdNam = list[i].prpdNam;
                                                        } else {
                                                            prpdNam = "";
                                                        }
                                                        if (list[i].prpdOrdNo != null) {
                                                            prpdOrdNo = list[i].prpdOrdNo;
                                                        } else {
                                                            prpdOrdNo = "";
                                                        }
                                                        if (list[i].prpdId != null) {
                                                            prpdId = list[i].prpdId;
                                                        } else {
                                                            prpdId = "";
                                                        }
                                                        if (list[i].prpdPlaStaDat != null) {
                                                            prpdPlaStaDat = list[i].prpdPlaStaDat;
                                                        } else {
                                                            prpdPlaStaDat = "";
                                                        }
                                                        if (list[i].prpdPlaEndDat != null) {
                                                            prpdPlaEndDat = list[i].prpdPlaEndDat;
                                                        } else {
                                                            prpdPlaEndDat = "";
                                                        }
                                                        if (list[i].prpdDepId != null) {
                                                            prpdDepId = list[i].prpdDepId;
                                                        } else {
                                                            prpdDepId = "";
                                                        }
                                                        if (list[i].prpdRem != null) {
                                                            prpdRem = list[i].prpdRem;
                                                        } else {
                                                            prpdRem = "";
                                                        }

                                                    }
                                                    planOptionListEml += "<option " + selected + " data-propCod='" + planData[j].prpdCod + "' data-prpdOrdNo='" + planData[j].prpdOrdNo + "' value='" + planData[j].prpdNam + "'>" + planData[j].prpdNam + "</option>";
                                                }
                                                planOptionListEml += "</select></span>";
                                                planOptionListEml += "<input style='width:170px;position:absolute;left:0px;' name='prpdNam' maxlength='255' oninput='clearRelDat(this)' value='"+prpdNam+"'/>";
                                                planOptionListEml += "<input name='prpdCod' type='hidden' style='display: none' value='" + prpdCod + "' />";
                                                planOptionListEml += "<input name='prpdOrdNo' type='hidden' style='display: none' value='" + prpdOrdNo + "' />";
                                                planOptionListEml += "<input name='prpdId' type='hidden' style='display: none' value='" + prpdId + "' /></div>";
                                                let tdEl = new Array();
                                                let newOrderNo = getNewOrderNo();
                                                tdEl.push('<td name="orderNo">' + newOrderNo + '</td>');
                                                tdEl.push('<td>' + planOptionListEml + '</td>');
                                                tdEl.push('<td><input class="form-control changeCursorIco" name="prpdPlaStaDat" type="text" style="outline：none;" readOnly="readonly" value="' + prpdPlaStaDat + '" alt="点击选择开始时间"/></td>');
                                                tdEl.push('<td><input class="form-control changeCursorIco" name="prpdPlaEndDat" type="text" style="outline：none;" readOnly="readonly" value="' + prpdPlaEndDat + '" alt="点击选择结束时间"/></td>');
                                                deptOptionList = "<select class='form-control' name='prpdDepId' style='border:none;outline：none;'>";
                                                deptOptionList += "<option value=''>&nbsp;</option>";
                                                for (let i = 0; i < deptList.length; i++) {
                                                    if(prpdDepId===deptList[i].id){
                                                        deptOptionList += "<option selected='selected' value='" + deptList[i].id + "'>" + deptList[i].name + "</option>";
                                                    }else{
                                                        deptOptionList += "<option value='" + deptList[i].id + "'>" + deptList[i].name + "</option>";
                                                    }
                                                }
                                                deptOptionList += "</select>";
                                                tdEl.push('<td>'+deptOptionList+'</td>');
                                                tdEl.push('<td><textarea class="form-control" name="prpdRem" type="text" maxlength="255" style="outline：none;border: none;width: 100%;height: 30px;outline: none;resize: none;">' + prpdRem + '</textarea></td>');
                                                if (i === list.length - 1) {
                                                    tdEl.push('<td name="oper" style="border:none;width:60px;"><button type="button" onclick="addRow(this)" style="border:none;background:transparent;color:green;font-size: 18px"><i class="fa fa-plus"></i></button><button onclick="subtractRow(this)" style="border:none;background:transparent;color:red;font-size: 18px"> <i class="fa fa-close"></i></button></td>');
                                                } else {
                                                    tdEl.push('<td name="oper" style="border:none;width:60px;"><button onclick="subtractRow(this)" style="border:none;background:transparent;color:red;font-size: 18px;margin-left:25.84px;"> <i class="fa fa-close"></i></button></td>');
                                                }
                                                $("#formTable").append('<tr id="dataRow_' + newOrderNo + '">' + tdEl + '</tr>')
                                                $("#formTable [name='prpdPlaStaDat']").datepicker({
                                                    format: "yyyy-mm-dd",
                                                    language: "zh-cn",
                                                    autoclose: true,
                                                    todayHighlight: true,
                                                    clearBtn: true
                                                });
                                                $("#formTable [name='prpdPlaEndDat']").datepicker({
                                                    format: "yyyy-mm-dd",
                                                    language: "zh-cn",
                                                    autoclose: true,
                                                    todayHighlight: true,
                                                    clearBtn: true
                                                });

                                            }
                                            if(isHaveProduction===false){
                                                $("#btn_addRow").click();
                                            }
                                        }
                                    },
                                    error: function () {
                                        js.modal.fail();
                                    }
                                });
                            }
                        }
                    });

                }
            },
            error: function () {
                js.modal.fail();
            }
        });
    }

    /**
     * 更新相关数据
     * @param obj
     */
    function updRelDat(obj) {
        $(obj).parent().parent().find("[name='prpdNam']").val($(obj).find('option:selected').text());
        $(obj).parent().parent().find("[name='prpdCod']").val($(obj).find('option:selected').attr('data-propCod'));
        $(obj).parent().parent().find("[name='prpdOrdNo']").val($(obj).find('option:selected').attr('data-prpdOrdNo'));
    }

    /**
     * 如果输入框内容改变则清空码和生产令
     * 如果内容与计划名完全相同则把匹配到数据赋在控件上
     * @param obj
     */
    function clearRelDat(obj) {
        $(obj).parent().parent().find("[name='prpdCod']").val(null);
        let thisVal = $(obj).val();
        for (let i = 0; i < planData.length; i++) {
            if(thisVal === planData[i].prpdNam){
                $(obj).parent().parent().find("[name='prpdCod']").val(planData[i].prpdCod);
                $(obj).parent().parent().find("[name='prpdOrdNo']").val(planData[i].prpdOrdNo);
                break;
            }
        }
    }
</script>
</body>
</html>